/**
 * Created by m on 2018/12/25.
 */
var ip = 'http://192.168.84.159:8088';//正式
// var ip = 'http://192.168.83.128:8088';//测试
var salt = 'TG*&)91MG*&^';
var url = window.location.href;
var urlZ = url.split("token=");
var _loginName = GetRequest().loginName;
var _token = urlZ[1];
var urlY = url.split("strategyId=");
var _urlStrategyId =urlY[1];

//获取url中的用户loginName
function GetRequest() {
    var url = location.search;//获取url中"?"符后的字串
    var theRequest = new Object();
    if(url.indexOf("?") != -1){
        var str = url.substr(1);
        strs = str.split("&");
        for(var i = 0; i < strs.length; i++){
            theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
        }
    }
    return theRequest;
}
//时间转换
function getMyDate(str) {
    var oDate = new Date(str),
        oYear = oDate.getFullYear(),
        oMonth = oDate.getMonth() + 1,
        oDay = oDate.getDate(),
        oHour = oDate.getHours(),
        oMin = oDate.getMinutes(),
        oSen = oDate.getSeconds(),
        oTime = oYear + '-' + getzf(oMonth) + '-' + getzf(oDay) + ' ' + getzf(oHour) + ':' + getzf(oMin) + ':' + getzf(oSen);//最后拼接时间
    return oTime;
};

function getzf(num) {
    if (parseInt(num) < 10) {
        num = '0' + num;
    }
    return num;
}

//编写cookie
function SetCookie(name,value) {
    var Days = 1; //此 cookie 将被保存 30 天
    var exp = new Date();  //new Date("December 31, 9998");
    exp.setTime(exp.getTime() + Days*24*60*60*1000);
    document.cookie = name + "=" + encodeURIComponent(value) + ";expires=" + exp.toGMTString();
}
 //获取cookie
function getCookie(name) {
    var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
    if(arr != null){
        return unescape(arr[2]);
    }
    return null;
}
//删除cookie
function delCookie(name) {
    var exp = new Date();
    exp.setTime(exp.getTime() -1);
    var cval = getCookie(name);
    if(cval != null){
        document.cookie= name + "="+cval+";expires="+exp.toGMTString();
    }
}

//时间戳转datetime-local 使用方法            var timeNow = new Date(timestamp).Format("yyyy-MM-ddThh:mm:ss");
Date.prototype.Format = function (fmt) { //author: meizz
    var o = {
        "M+": this.getMonth() + 1,                 //月份
        "d+": this.getDate(),                    //日
        "h+": this.getHours(),                   //小时
        "m+": this.getMinutes(),                 //分
        "s+": this.getSeconds(),                 //秒
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度
        "S": this.getMilliseconds()             //毫秒
    };
    if (/(y+)/.test(fmt))
        fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
        if (new RegExp("(" + k + ")").test(fmt))
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
};
//距今多久
function transDate(mescStr) {
    var n = mescStr;
    var date = new Date(n);
    // var Y = date.getFullYear() + '-';
    var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
    var D = date.getDate() < 10 ? '0' + date.getDate() + ' ' : date.getDate() + ' ';
    var H = date.getHours() + ':';
    var Mi = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes();


    var M2 = date.getMonth() +1;
    var D2 = date.getDate();
    var H2 = date.getHours();
    var Mi2 = date.getMinutes();

    var date1 = new Date();
    var M1 = date1.getMonth()+1;
    var D1 = date1.getDate();
    var H1 = date1.getHours();
    var Mi1 = date1.getMinutes();
    if(M1 > M2 || D1 > D2){
        return (getMyDate(date))
    }
    else if (H1-H2>1){
        var H3= H1-H2-1;
        return (H3+"小时前")
    }
    else if (Mi1 - Mi2 > 1) {
        var Mi3 = Mi1 - Mi2 -60;
        return (Math.abs(Mi3) + "分钟前")
    }
    else{
        return "刚刚"
    }
}

//表头固定
// var tableCont = document.querySelector('.Hedtable');
// var tableCont = document.querySelector('#strategyTableDiv');
/**
 * scroll handle
 * @param {event} e -- scroll event
 */
function scrollHandle(e) {
    // console.log(this)
    var scrollTop = this.scrollTop;
    this.querySelector('thead').style.transform = 'translateY(' + scrollTop + 'px)';
}

// tableCont.addEventListener('scroll', scrollHandle);